import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import math
from sklearn import preprocessing
impacts = []# 影响因子列表
def entropyWeight(data):
    data = np.asarray(data[impacts])

    p = data / data.sum(axis=0)
    # 计算熵值
    E = np.nansum(-p * np.log(p) / np.log(len(data)), axis=0)

    # 计算权值
    return (1-E) / (1-E).sum()
def topsis(data1, weights=None, ele = 402):
    
    t = np.array(data1[impacts]).reshape(ele, len(impacts))
    min_max_scaler = preprocessing.MinMaxScaler()
    data = pd.DataFrame(min_max_scaler.fit_transform(t))

    z = pd.DataFrame([data.min(), data.max()], index = ['负理想解', '正理想解'])

    weights = entropyWeight(data) if weights is None else np.array(weights)





